package com.ambimmort.shj.action.policybank;

import com.ambimmort.shj.service.policybank.PolicybankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created by Administrator on 2015/7/30.
 */
@Controller("/action/policy/deletePRI.do")
public class Delete {
    @Autowired
    private PolicybankService policybankService;

    /**
     *
     * @param request 接收
     * @param response 响应
     * @param id //创建策略仓库类型名称
     * @param type 创建策略仓库类型名称
     * @param instance 创建策略仓库实例名称
     * @return
     * @throws IOException
     * @throws IOException
     */
    @RequestMapping("/action/policy/deletePRI.do")
    @ResponseBody
    public String action_PolicybankDelete(HttpServletRequest request, HttpServletResponse response,@RequestParam("id") String id, @RequestParam("type") String type, @RequestParam("instance") String instance) throws IOException, IOException {
        System.out.println(id+"|||"+type+"|||"+instance);
        String username = null;
        try {
            HttpSession hsession = request.getSession(false);
            username = hsession.getAttribute("name").toString();
        } catch (Exception e) {
            response.sendRedirect("/WebManage/404.html");
        }

        System.out.println("type" + type);
        System.out.println("instance" + instance);
        System.out.println("username" + username);

        try {
            policybankService.deleteDomain(id,type, instance);

            return  "{\"result\":\"true\"}";
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return "{\"result\":\"false\"}";

        }
    }
}
